import { getDetail } from '@/services/api';

export default {
  namespace: 'contentPage',

  state: {
    detailInfo: {},
  },

  effects: {
    *getDetailInfo({ payload }, { call, put }) {
      console.log('新闻详情：', payload);
      try {
        const response = yield call(getDetail, payload);
        if (response) {
          yield put({
            type: 'setDetailInfo',
            payload: {
              detailInfo: response,
            },
          });
        }
      } catch (e) {
        console.log('Error:', e);
      }
    },
  },
  reducers: {
    setDetailInfo(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
